<template>
    <div class="container"  ref="containerRef">
      <div class="switch" @click="showOrHideMainPage">
        <!-- <AppstoreOutlined /> -->
      </div>
      <div class="topBox" ref="topBoxRef">
        <img alt="" class="topBg" />
        <img  alt="" class="shine" />
        <div class="leftLine" />
        <div class="rightLine" />
        <div class="title">
          <span>
            {{ 1111 }}
          </span>
        </div>
      </div>
      <div class="leftBox" ref="leftBoxRef">
        <div class="item">
          <Border1 title="1">
            {{ 2}}
          </Border1>
        </div>
        <div class="item">
          <Border1>
            11
          </Border1>
        </div>
      </div>
      <div class="rightBox" ref="rightBoxRef">
        <div class="item">
          <Border1 title="1">
           11
          </Border1>
        </div>
        <div class="item">
          <Border1>
          11
          </Border1>
        </div>
      </div>
      <div class="tooltip" ref="tooltipRef"></div>
    </div>
</template>

<script>
/**
 * 地图展示
 */

import useMoveTo from "@/hooks/useMoveTo";
import Border1 from "./Border1.vue";
import { useGlobalContext } from "@/hooks/useGlobalContext";
import {gsap} from "gsap"



const cameraInitPosition = { x: 0, y: -20, z: 80 }; // 相机初始位置
const mapInitPosition = { x: 0, y: 6, z: 0 }; // 地图初始位置
const mapDepth = 6; // 地图板块深度
const mapColor = "#008170"; // 地图表面颜色
const mapSideColor = "#1AACAC"; // 地图侧面颜色
const mapHoverColor = "#005B41"; // hover后的地图表面颜色

export default {
  name: 'Test',
  components: {
    Border1
  },
  data() {
    return {
    //   raycaster: new THREE.Raycaster(),

      controls: null,
      map: null,
      mouse: null,
      lastPick: null,
      showMainPage: true,
      containerRef: null,
      tooltipRef: null,
      topBoxRef: null,
      leftBoxRef: null,
      rightBoxRef: null,
      globalContext: null
    }
  },
  created() {
    this.globalContext = useGlobalContext();
  },
  mounted() {
    this.animation()
    this.tooltipRef = this.$refs.tooltipRef
    this.leftBoxRef = this.$refs.leftBoxRef
    this.containerRef = this.$refs.containerRef
    this.rightBoxRef = this.$refs.rightBoxRef
    const { restart: topRestart, reverse: topReverse } = useMoveTo(
      this.topBoxRef,
      "toBottom",
      0.6
    );
    const { restart: leftRestart, reverse: leftReverse } = useMoveTo(
      this.leftBoxRef,
      "toRight",
      0.8,
      0.5
    );
    const { restart: rightRestart, reverse: rightReverse } = useMoveTo(
      this.rightBoxRef,
      "toLeft",
      0.8,
      0.5
    );
    console.log(topRestart,topReverse)
    this.moveControls = {
      topRestart,
      topReverse,
      leftRestart,
      leftReverse,
      rightRestart,
      rightReverse
    };
    this.showOrHideMainPage()
    this.$watch(
      () => this.globalContext.menuWidth,
      () => {
        this.resize();
      }
    );
  },
  methods: {
    animation() {
        gsap.to(".leftBox", {duration:0.8, x:300})
        gsap.to(".rightBox", {duration:0.8, x: 0})
    },
    showOrHideMainPage() {
      if (this.showMainPage) {
        console.log(this.moveControls.topReverse())
        this.moveControls.topReverse();
        this.moveControls.leftReverse();
        this.moveControls.rightReverse();
      } else {
        this.moveControls.topRestart();
        this.moveControls.leftRestart();
        this.moveControls.rightRestart();
      }
      this.showMainPage = !this.showMainPage;
    },
    // onMouseMove(e) {
    //   if (this.tooltipRef) {
    //     if (!this.mouse) {
    //       this.mouse = new THREE.Vector2();
    //     }
    //     const { clientX, clientY } = e;
    //     if (new THREE.Vector2()) {
    //       this.mouse.x =
    //         ((clientX - this.globalContext.menuWidth) /
    //           (window.innerWidth - this.globalContext.menuWidth)) *
    //           2 -
    //         1;
    //     }
    //     this.mouse.y =
    //       -(
    //         (clientY - this.globalContext.headHeight) /
    //         (window.innerHeight - this.globalContext.headHeight)
    //       ) *
    //         2 +
    //       1;

    //     this.tooltipRef.style.left = `${
    //       clientX - this.globalContext.menuWidth + 4
    //     }px`;
    //     this.tooltipRef.style.top = `${
    //       clientY - this.globalContext.headHeight + 4
    //     }px`;
    //   }
    // },
    

    
  }
}
</script>



<style scoped lang="scss">
.container {
  width: 100%;
  height: 100%;
  background-color: #000808;
  overflow: hidden;
  position: relative;

  .switch {
    position: absolute;
    top: 40px;
    right: 20px;
    z-index: 2;
    cursor: pointer;
    :deep(svg) {
      width: 32px;
      height: 32px;
      path {
        fill: #00c6c6;
      }
    }
  }

  $topBoxHeight: 80px;
  $leftBoxWidth: 30%;
  $rightBoxWidth: 30%;

  .topBox {
    position: absolute;
    top: 0;
    width: 100%;
    height: $topBoxHeight;
    z-index: 1;
    transform: translate(0px, -$topBoxHeight);

    img {
      width: 100%;
      height: 61px;
    }
    $marginTop: 20px;
    $lineWidth: 120px;
    $lineHeight: 4px;
    .topBg {
      position: absolute;
      top: $marginTop;
      left: 0;
      right: 0;
      width: 100%;
      height: 61px;
    }
    .shine {
      position: absolute;
      top: $marginTop + 31px;
      left: 0;
      right: 0;
      width: 808px;
      height: 55px;
      margin: 0 auto;
    }
    .leftLine {
      position: absolute;
      top: calc($marginTop - calc($lineHeight / 2));
      left: 4%;
      width: $lineWidth;
      height: $lineHeight;
      border-radius: calc($lineHeight / 2);
      background-image: linear-gradient(to left, #b5eff6, #008f8f, #003d3d);
    }
    .rightLine {
      position: absolute;
      top: calc($marginTop - calc($lineHeight / 2) + 1px);
      right: 4%;
      width: $lineWidth;
      height: $lineHeight;
      border-radius: calc($lineHeight / 2);
      background-image: linear-gradient(to right, #b5eff6, #008f8f, #003d3d);
    }
    .title {
      position: absolute;
      top: 16px;
      left: 0;
      right: 0;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      span {
        text-align: center;
        font-size: 32px;
        font-weight: 600;
        font-family: "SourceHanSansCN-Bold" !important;
        background-image: linear-gradient(
          to right,
          #003d3d,
          #008f8f,
          #00cfcf,
          #008f8f,
          #003d3d
        );
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
      }
    }
  }
  .leftBox {
    position: absolute;
    left: -300px;
    top: $topBoxHeight;
    width: $leftBoxWidth;
    height: calc(100% - $topBoxHeight);
    z-index: 1;
    transform: translate(-$leftBoxWidth, 0px);

    .item {
      width: 100%;
      height: 40%;
      padding: 20px;
      &:last-child {
        height: 60%;
      }
    }
  }
  .rightBox {
    position: absolute;
    right: 150px;
    top: $topBoxHeight;
    width: $rightBoxWidth;
    height: calc(100% - $topBoxHeight);
    z-index: 1;
    transform: translate($leftBoxWidth, 0px);

    .item {
      width: 100%;
      height: 40%;
      padding: 14px;
      &:last-child {
        height: 60%;
      }
    }
  }
  .tooltip {
    position: absolute;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 600;
    color: #000;
    background-color: #ffffff;
    border-radius: 4px;
    visibility: hidden;
    z-index: 10;
  }
}
</style>
